package com.superteam.mac.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.superteam.mac.mode.MacRealTimeBean;

public class MacStautData extends HttpServlet {
	private static final long serialVersionUID = -5588664779025335130L;
	public static Map<String,MacRealTimeBean> machines = new HashMap<String,MacRealTimeBean>();
		
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//request.setCharacterEncoding("GBK");
		String data = request.getParameter("data");
		System.out.println("====="+data);
		try{
    	String [] strs = data.split("\\|");//车间1,0101,2011-4-3 19:11:29,故障,1,1|
    	for(String str:strs)
    	{
    		String [] s = str.split(",");
    		if(s.length>=6)
    		{
    			MacRealTimeBean bean = new MacRealTimeBean();
        		bean.setWorkShopCode(s[0]);
        		bean.setMachineCode(s[1]);
        		bean.setRecTime(s[2]);
        		bean.setStateType(s[3]);
        		bean.setIsAlarm(s[4]);
        		bean.setDuration(s[5]);
        		
        		bean.setMachineName(RealTimeUtil.getMachineName(s[1]));
        		addData(bean);
    		}
    		
    	}
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		
	}
	public static void addData(MacRealTimeBean bean)
	{
		machines.put(bean.getWorkShopCode()+bean.getMachineCode(), bean);
		
	}

}
